var g, app = getApp(), page = app.page, request = app.util.request, route = app.route, toast = app.toast;

function getList() {
    request({
        url: "myEarnings",
        data: {
            user_id: app.userInfo.id || wx.getStorageSync("userInfo").id,
            value: g.data.keyword,
            page:  g.data.page,
            number: 10
        },
        success: function(t) {
          let list = g.data.list
          if(g.data.page == 1){
            list = t.list
            g.setData({
              statistics: t,
            })
          } else {
            list = list.concat(t.list)
          }
          g.setData({
            list
          })
          wx.stopPullDownRefresh()
        }
    });
}

page({
    data: {
        cur: -1,
        no_orders: app.srcRoot + "no_order.png",
        keyword: '',
        statistics:{
          day_fee: 0,
          day_sell: 0,
          last_month_fee: 0,
          last_month_sell: 1,
          month_fee: 0,
          month_sell: 1,
        },
        page: 1,
        list: []
    },
    onLoad: function(t) {
        g = this, getList();
    },
    getMore(){
      g.setData({
        page: g.data.page + 1
      })
      getList()
    },
    onPullDownRefresh: function() {
      this.setData({
        page: 1
      });
      getList();
    },
    tabSelect: function(t) {
        this.setData({
            cur: t.currentTarget.dataset.index,
            page: 1
        });
        getList();
    },
    keywordSearch: function(){
      getList()
    },
    input: function(a) {
      let keyword = a.detail.value;
      g.setData({
        keyword
      })	
    },
});